package com.meilai.project.service.media.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meilai.project.dto.business.media.MediaTypeSpecsDTO;
import com.meilai.project.entity.media.MediaPointTypeSpecsRelation;
import com.meilai.project.exception.CommonException;
import com.meilai.project.mapper.business.media.MediaPointMapper;
import com.meilai.project.mapper.business.media.MediaPointTypeSpecsRelationMapper;
import com.meilai.project.service.media.MediaPointTypeSpecsRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author ljy
 * @Date 2022/5/27 9:06
 */
@Service
public class MediaPointTypeSpecsRelationServiceImpl extends ServiceImpl<MediaPointTypeSpecsRelationMapper, MediaPointTypeSpecsRelation> implements MediaPointTypeSpecsRelationService {

    @Autowired
    private MediaPointMapper mediaPointMapper;

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public boolean editList(MediaTypeSpecsDTO dto) {
        if (dto.getMedia_type_id() == null) {
            throw new CommonException("请先选择点位类型");
        }
        List<Long> listByMediaTypeId = mediaPointMapper.getListByMediaTypeId(dto.getMedia_type_id());
//        List<MediaPointTypeSpecsRelation> list = new ArrayList<>();
//        List<Long> ids = new ArrayList<>();
        try {
            if (listByMediaTypeId.size() > 0) {
                mediaPointMapper.updateByMediaTypeId(dto);
                // 插入普通规格
           /*     for (Long media_point_id : listByMediaTypeId) {
                    ids.add(media_point_id);
                    if (dto.getMedia_type_specs_ids() != null) {
                            MediaPointTypeSpecsRelation relation = new MediaPointTypeSpecsRelation();
                            relation.setMedia_point_id(media_point_id);
                            relation.setMedia_type_specs_id(dto.getMedia_type_specs_ids());
                            list.add(relation);
                    }
                }
                if (CollectionUtils.isNotEmpty(ids)) {
                    List<Long> mediaPointRelationIds = mediaPointMapper.getMediaPointRelationIds(ids);
                    baseMapper.deleteBatchIds(mediaPointRelationIds);
                }
                saveBatch(list);*/
            } else {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
